package com.example.composedemo.widget

import androidx.compose.foundation.BorderStroke
import androidx.compose.foundation.interaction.MutableInteractionSource
import androidx.compose.foundation.interaction.collectIsDraggedAsState
import androidx.compose.foundation.interaction.collectIsFocusedAsState
import androidx.compose.foundation.interaction.collectIsPressedAsState
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.size
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Done
import androidx.compose.material.icons.filled.Favorite
import androidx.compose.material.icons.filled.KeyboardArrowUp
import androidx.compose.material3.Button
import androidx.compose.material3.ButtonDefaults
import androidx.compose.material3.ExtendedFloatingActionButton
import androidx.compose.material3.FloatingActionButton
import androidx.compose.material3.Icon
import androidx.compose.material3.IconButton
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.remember
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp

@Preview
@Composable
fun ButtonTest() {

    val interactionSource = remember { MutableInteractionSource() }
    // 是否按下
    val pressState = interactionSource.collectIsPressedAsState()
    // 是否拖拽
    val dragState = interactionSource.collectIsDraggedAsState()
    // 是否获取焦点
    val focusState = interactionSource.collectIsFocusedAsState()
    val borderColor = if (pressState.value) {
        Color.Green
    } else {
        Color.White
    }

    Column {
        Button(
            onClick = { },
            enabled = true,
            interactionSource = interactionSource,
            border = BorderStroke(2.dp, borderColor)
        ) {
            Icon(imageVector = Icons.Filled.Done, contentDescription = null)
            Spacer(modifier = Modifier.size(ButtonDefaults.IconSpacing))
            Text(text = "我是按钮")
        }

        IconButton(onClick = { }) {
            Icon(imageVector = Icons.Filled.Favorite, contentDescription = null)
        }

        FloatingActionButton(onClick = { /*TODO*/ }) {
            Icon(imageVector = Icons.Filled.KeyboardArrowUp, contentDescription = null)
        }

        ExtendedFloatingActionButton(onClick = { /*TODO*/ }) {
            Icon(imageVector = Icons.Filled.KeyboardArrowUp, contentDescription = null)
            Spacer(modifier = Modifier.size(ButtonDefaults.IconSpacing))
            Text(text = "我是扩展按钮")
        }
    }
}